#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 110;

struct student
{
	string xm;
	int qm, py;
	char gb, xb;
	int lw;
	ll jj;
	int xh;
}stu[N];

bool cmp(student x,student y){
	if (x.jj == y.jj) return x.xh < y.xh;
	else return x.jj > y.jj;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> stu[i].xm >> stu[i].qm >> stu[i].py >> stu[i].gb >> stu[i].xb >> stu[i].lw;
		stu[i].xh = i;
		if (stu[i].qm > 80 && stu[i].lw >= 1) stu[i].jj += 8000;
		if (stu[i].qm > 85 && stu[i].py > 80) stu[i].jj += 4000;
		if (stu[i].qm > 90) stu[i].jj += 2000;
		if (stu[i].qm > 85 && stu[i].xb == 'Y') stu[i].jj += 1000;
		if (stu[i].py > 80 && stu[i].gb == 'Y') stu[i].jj += 850;
		sum += stu[i].jj;
	}
	sort(stu, stu + n, cmp);
	cout << stu[0].xm << '\n' << stu[0].jj << '\n' << sum << '\n';
	return 0;
}